package com.lewin.ringroad.net.message;

import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * 事件检测（0xB1）
 *
 * @author Jun
 * @since 1.0.0
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class EventCheckMessage extends BaseMessage {
    //@formatter:off

    /** POS 线位置 */
    private float posLocation;
    /** 检测通道号 */
    private short channelCode;
    /** 交通事件类型 */
    private byte type;
    /** 置信度 */
    private float stability;
    /** 纬度 */
    private double latitude;
    /** 经度 */
    private double longitude;
    /** 时间戳 */
    private long timestamp;
    /** 图片长度 */
    private long imgLength;
    /** 图片 */
    private byte[] img;

    //@formatter:on

    @Override
    public BaseMessage parse(ByteBuf buf) {
        this.posLocation = buf.readFloatLE();
        this.channelCode = buf.readUnsignedByte();
        this.type = buf.readByte();
        this.stability = buf.readFloatLE();
        this.latitude = buf.readDoubleLE();
        this.longitude = buf.readDoubleLE();
        this.timestamp = buf.readLongLE() - 28800; // 东八区
        this.imgLength = buf.readUnsignedIntLE();
        if (this.imgLength != 0) {
            this.img = new byte[(int) this.imgLength];
            buf.readBytes(this.img);
        }

        return this;
    }
}
